package com.adnaan.backend.service.storage;

import com.adnaan.backend.config.StorageConfig;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class StorageFactory {
    private final Map<String, StorageService> storageServiceMap;
    private final StorageConfig storageConfig;

    public StorageFactory(Map<String, StorageService> storageServiceMap, StorageConfig storageConfig) {
        this.storageServiceMap = storageServiceMap;
        this.storageConfig = storageConfig;
    }

    public StorageService getStorageService() {
        String type = storageConfig.getType();
        StorageService storageService = switch (type.toLowerCase()) {
            case "local" -> storageServiceMap.get("localStorageService");
            case "qiniu" -> storageServiceMap.get("qiniuStorageService");
            case "aliyun" -> storageServiceMap.get("aliyunStorageService");
            default -> throw new IllegalArgumentException("Unsupported storage type: " + type);
        };
        if (storageService == null) {
            throw new IllegalArgumentException("Storage service not found for type: " + type);
        }
        return storageService;
    }
} 